<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('账本分类列表')" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>分类名称：</label>
                                <input type="text" name="className"/>
                            </li>
                            <li>
                                <label>分类类型：</label>
                                <select name="classType" th:with="type=${@dict.getType('account_income_pay')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>

                            <li>
                                <label>分类状态：</label>
                                <select name="classStatus" th:with="type=${@dict.getType('sys_normal_disable')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="classif:account:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="classif:account:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="classif:account:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="classif:account:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('classif:account:edit')}]];
        var removeFlag = [[${@permission.hasPermi('classif:account:remove')}]];
        var classTypeDatas = [[${@dict.getType('account_income_pay')}]];
        var classStatusDatas = [[${@dict.getType('sys_normal_disable')}]];
        var prefix = ctx + "account/classif";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "账本分类",
                columns: [{
                    checkbox: true,
                    formatter: function (value, row, index) {
                        // 1为已使用，已使用的则不允许删除
                        if($.common.equals("1", row.isBuy)){
                            return { disabled : true}
                        } else {
                            return { disabled : false}
                        }
                    }
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'classIcon',
                    title: '分类图标',
                    formatter: function (value, row, index) {
                        // 根据 value 的值动态选择图标
                        var iconColor = 'gray'; // 默认颜色
                        if ("1"==row.status){ // 收入
                            iconColor = '#5cb85c'
                        }else if ("2"==row.status){ // 支出
                            iconColor = '#d9534f'
                        }else if ("3"==row.status){ // 不计入
                            iconColor = '#f0ad4e'
                        }

                        return "<i class='" + value + "' style='color: " + iconColor + "; font-size: 18px;'></i> ";
                    }
                },
                {
                    field: 'className',
                    title: '分类名称'
                },
                {
                    field: 'classType',
                    title: '分类类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(classTypeDatas, value);
                    }
                },
                {
                    field: 'classIntroduce',
                    title: '分类介绍'
                },
                {
                    field: 'orderNum',
                    title: '显示顺序'
                },
                {
                    field: 'classStatus',
                    title: '分类状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(classStatusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');

                        // 如果 row.isBuy 为 1 则删除按钮禁用
                        if($.common.equals("1", row.isBuy)){
                            actions.push('<a class="btn btn-danger btn-xs disabled" href="javascript:void(0)"><i class="fa fa-remove"></i>删除</a>');
                        }else{
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>
